﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaixin.Components.InterFace;

namespace Kaixin.Components.Net
{
    /// <summary>
    /// 开心网的公共数据获取机器人
    /// 主要功能是降低被监控账户的登录次数达到降低被封号的风险
    /// 创建：2009-12-9 
    /// 版本：1.1
    /// 作者：吴鸣震
    /// </summary>
    public class KaiXinPublicRobot:IAccessPage
    {
        #region IAccessPage 成员

        public HtmlAgilityPack.HtmlDocument AccessPage(string url)
        {
            return PublicRobotFactory.GetPublicRobot().AccessPage(url);
        }

        #endregion


        #region private Factory class
        /// <summary>
        /// 采用私有工厂类随机返回多个公用账号
        /// </summary>
        private class PublicRobotFactory
        {
            #region private
            private static List<Robot> _listRobot = null;
            //公共数据获取账号
            private static readonly string[] _emails = { 
                                                "zachary01@yahoo.cn", 
                                                "zachary02@yahoo.cn", 
                                                "zachary03@yahoo.cn", 
                                                "zachary04@yahoo.cn", 
                                                "zachary05@yahoo.cn",
                                                "zachary06@yahoo.cn"
                                            };
            private static readonly Random _random = new Random();
            #endregion
            //静态构造类
            static PublicRobotFactory()
            {
                _listRobot = new List<Robot>();
                foreach (var email in _emails)
                {
                    _listRobot.Add(new Robot(email, "123456"));//账号统一密码
                }
            }

            public static Robot GetPublicRobot()
            {
                int index = _random.Next(_emails.Length);
                return _listRobot[index];
            }
        }
        #endregion
    }
}
